home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / regenwizardaw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-02-15  |  7.1 KB  |  284 lines

  1. // RegenWizardaw.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "RegenWizard.h"
  6. #include "RegenWizardaw.h"
  7.  
  8.  
  9. #ifdef _PSEUDO_DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. CRegenWizardAppWiz::CRegenWizardAppWiz() :
  15.     CCustomAppWiz(),
  16.     m_strRegistryKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"),
  17.     m_clsFirstStep(this),
  18.     m_clsSecondStep(this),
  19.     m_clsRegenProps(this),
  20.     m_clsEvents(this),
  21.     m_clsFilterInfo(this),
  22.     m_clsToolBasicInfo(this)
  23. {
  24. }
  25.  
  26. bool CRegenWizardAppWiz::Try(CString strCADName)
  27. {
  28.     unsigned char    *str = new unsigned char[255];
  29.     unsigned long    ulTmp, 
  30.                     ulLength = 255;
  31.     HKEY            hKey = 0;
  32.     CString            strPath;
  33.  
  34.     RegOpenKeyEx(HKEY_LOCAL_MACHINE, m_strRegistryKey + strCADName, 0, KEY_EXECUTE, &hKey);
  35.     if (!hKey) return false;
  36.     
  37.     RegQueryValueEx(hKey, "Path", NULL, &ulTmp, str, &ulLength);
  38.  
  39.     strPath    = str;
  40.     strPath = strPath.Left(strPath.GetLength() - 8);
  41.  
  42.     m_strTCW            = strPath + (CString)"Program\\";
  43.     m_strSDKInclude        = strPath + (CString)"SDK\\Include\\";
  44.     m_strDestination    = strPath + (CString)"Program\\Regens";
  45.  
  46.     m_clsSecondStep.m_strDestination    = m_strDestination;
  47.     m_clsSecondStep.m_strSDKInclude        = m_strSDKInclude;
  48.     
  49.     delete[] str;
  50.     return true;
  51. }
  52.  
  53. void CRegenWizardAppWiz::CreatePathVariables()
  54. {
  55.     if (Try("Tcw70.Exe")) return;
  56.     if (Try("Tcw80.Exe")) return;
  57.     if (Try("Tcw90.Exe")) return;
  58.     if (Try("Tcw10.Exe")) return;
  59.     if (Try("Tcw11.Exe")) return;
  60. }
  61.  
  62.  
  63. void CRegenWizardAppWiz::FillDictionary()
  64. {
  65.     CString    cstrStdAfxUUID        = GenGUID();
  66.     cstrStdAfxUUID.Replace("-","_");
  67.  
  68.     m_Dictionary[_T("Project_TypeLibrary_GUID")]    = GenGUID();
  69.     m_Dictionary[_T("Regen_COClass_GUID")]            = GenGUID();
  70.     m_Dictionary[_T("Regen_Interface_GUID")]        = GenGUID();
  71.  
  72.     m_Dictionary[_T("STD_AFX_GUID")]                = cstrStdAfxUUID;
  73.  
  74.     m_Dictionary[_T("SDKIncludeDirectory")]            = m_strSDKInclude;
  75.  
  76.     m_Dictionary[_T("CREATEEVENTSMASK.CPP")]        = _T("CREATEEVENTSMASK.CPP");
  77.  
  78.     m_Dictionary[_T("ALLEVENTS.IDL")]    = _T("EVENTS.IDL");
  79.     m_Dictionary[_T("ALLEVENTS.CPP")]    = _T("EVENTS.CPP");
  80.     m_Dictionary[_T("ALLEVENTS.H")]        = _T("EVENTS.H");
  81.  
  82.     m_Dictionary[_T("REGEN.IDL")]    = _T("REGEN.IDL");
  83.     m_Dictionary[_T("REGEN.CPP")]    = _T("REGEN.CPP");
  84.     m_Dictionary[_T("REGEN.H")]        = _T("REGEN.H");
  85.  
  86.     m_Dictionary[_T("TOOL.IDL")]    = _T("TOOL.IDL");
  87.     m_Dictionary[_T("TOOL.CPP")]    = _T("TOOL.CPP");
  88.     m_Dictionary[_T("TOOL.H")]        = _T("TOOL.H");
  89.  
  90.     m_Dictionary[_T("FILTER.IDL")]    = _T("FILTER.IDL");
  91.     m_Dictionary[_T("FILTER.CPP")]    = _T("FILTER.CPP");
  92.     m_Dictionary[_T("FILTER.H")]    = _T("FILTER.H");
  93.  
  94.     m_Dictionary[_T("TIE.IDL")]        = _T("TIE.IDL");
  95.     m_Dictionary[_T("TIE.CPP")]        = _T("TIE.CPP");
  96.     m_Dictionary[_T("TIE.H")]        = _T("TIE.H");
  97. }
  98.  
  99. // This is called immediately after the custom AppWizard is loaded.  Initialize
  100. //  the state of the custom AppWizard here.
  101. void CRegenWizardAppWiz::InitCustomAppWiz()
  102. {
  103.     // There are no steps in this custom AppWizard.
  104.     SetNumberOfSteps(4);
  105.  
  106.     // Add build step to .hpj if there is one
  107.     m_Dictionary[_T("HELP")] = _T("1");
  108.  
  109.     // Inform AppWizard that we're making a DLL.
  110.     m_Dictionary[_T("PROJTYPE_DLL")] = _T("1");
  111.  
  112.     m_iDlgNumber = 0;
  113.     
  114.     CreatePathVariables();
  115.     FillDictionary();
  116. }
  117.  
  118. // This is called just before the custom AppWizard is unloaded.
  119. void CRegenWizardAppWiz::ExitCustomAppWiz()
  120. {
  121.     // TODO: Add code here to deallocate resources used by the custom AppWizard
  122. }
  123.  
  124. CAppWizStepDlg* CRegenWizardAppWiz::RetDialog()
  125. {
  126.     switch (m_iDlgNumber)
  127.     {
  128.     case 1: return &m_clsFirstStep;
  129.     case 2: 
  130.         {
  131.             m_clsSecondStep.m_strDestination = m_strDestination;
  132.             return &m_clsSecondStep;
  133.         };
  134.     case 3:    return &m_clsEvents;
  135.     case 4:
  136.         {
  137.             if (m_Dictionary [_T("RegenCreating")]    == _T("Yes")) 
  138.                 return &m_clsRegenProps;
  139.             if (m_Dictionary [_T("ToolCreating")]    == _T("Yes"))
  140.                 return &m_clsToolBasicInfo;
  141.             if (m_Dictionary [_T("FilterCreating")]    == _T("Yes"))
  142.                 return &m_clsFilterInfo;
  143.             if (m_Dictionary [_T("TieCreating")]    == _T("Yes"))
  144.                 return NULL;
  145.         };
  146.     default: return NULL;
  147.     };
  148. }
  149.  
  150.  
  151. CAppWizStepDlg* CRegenWizardAppWiz::Back(CAppWizStepDlg* pDlg)
  152. {
  153.     m_iDlgNumber--;
  154.  
  155.     return    RetDialog();
  156. }
  157.  
  158. CAppWizStepDlg* CRegenWizardAppWiz::Next(CAppWizStepDlg* pDlg)
  159. {
  160.     m_iDlgNumber++;
  161.  
  162.     return RetDialog();
  163. }
  164.  
  165. BSTR MakeBSTR(CString str)
  166. {
  167.     return str.AllocSysString();
  168. }
  169.  
  170. BSTR MakeBSTR(const char* str)
  171. {
  172.     CString    cstr = str;
  173.     return    MakeBSTR(cstr);
  174. }
  175.  
  176. void CRegenWizardAppWiz::ChangeToolSettings(IConfiguration *pConfig, const char* strToolName, const char* strSetting, bool boolAdd)
  177. {
  178.     BSTR    bstrName    = MakeBSTR (strToolName);
  179.     BSTR    bstrSetting    = MakeBSTR (strSetting);    
  180.  
  181.     if (boolAdd) 
  182.         pConfig->AddToolSettings(bstrName, bstrSetting, varMissed);
  183.     else
  184.         pConfig->RemoveToolSettings(bstrName, bstrSetting, varMissed);
  185.  
  186.     ::SysFreeString (bstrName);
  187.     ::SysFreeString (bstrSetting);
  188. }
  189.  
  190.  
  191. void CRegenWizardAppWiz::ProcessConfig(IConfiguration *pConfig)
  192. {
  193.     ChangeToolSettings(pConfig, "midl.exe", "/mktyplib203", false);
  194.     ChangeToolSettings(pConfig, "midl.exe",    (CString)"/I\"" + m_strSDKInclude + "\"", true);
  195.  
  196.     ChangeToolSettings(pConfig, "cl.exe",    (CString)"/I\"" + m_strSDKInclude + "\"", true);
  197.  
  198.     ChangeToolSettings(pConfig, "link.exe",    (CString)"/out:\"" + m_strDestination+
  199.                                             (CString)"/"  + m_strRoot+(CString)".dll\"", true);
  200.     ChangeToolSettings(pConfig, "rc.exe",    (CString)"/i\"" + m_strSDKInclude + "\"", true);
  201. }
  202.  
  203. void CRegenWizardAppWiz::SomethingWasByDefault()
  204. {
  205.     m_Dictionary.Lookup(_T("root"), m_strRoot);
  206.  
  207.     // Set value of $$Doc$$, $$DOC$$
  208.     CString strDoc = m_strRoot.Left(6);
  209.     m_Dictionary[_T("Doc")] = strDoc;
  210.     strDoc.MakeUpper();
  211.     m_Dictionary[_T("DOC")] = strDoc;
  212.  
  213.     // Set value of $$MAC_TYPE$$
  214.     CString strTmp = m_strRoot.Left(4);
  215.     int nLen = strTmp.GetLength();
  216.     if (strTmp.GetLength() < 4)
  217.     {
  218.         CString strPad(_T(' '), 4 - nLen);
  219.         strTmp += strPad;
  220.     }
  221.     strTmp.MakeUpper();
  222.     m_Dictionary[_T("MAC_TYPE")] = strTmp;
  223. }
  224.  
  225. CString    CRegenWizardAppWiz::GenGUID()
  226. {
  227.     UUID            uuid;
  228.     unsigned char    *strUUID = NULL;
  229.     CString            strResult;
  230.  
  231.     UuidCreate(&uuid);
  232.     UuidToString(&uuid, &strUUID);
  233.  
  234.     strResult    = strUUID;
  235.     strResult.MakeUpper();
  236.  
  237.     RpcStringFree(&strUUID);
  238.  
  239.     return strResult;
  240. }
  241.  
  242. void CRegenWizardAppWiz::CustomizeProject(IBuildProject* pProject)
  243. {
  244.     SomethingWasByDefault();
  245.  
  246.     HRESULT            hRes        = S_OK;
  247.     IConfigurations    *pConfigs    = NULL;
  248.     IConfiguration    *pConfig    = NULL;
  249.     IEnumVARIANT    *pEachEnum    = NULL;
  250.     VARIANT            varPointer;
  251.     
  252.     varPointer.vt = VT_EMPTY;
  253.     try
  254.     {
  255.         hRes = pProject->get_Configurations(&pConfigs);
  256.         CHECK_HRESULT(hRes);
  257.  
  258.         hRes = pConfigs->get__NewEnum((IUnknown**)&pEachEnum);
  259.         CHECK_HRESULT(hRes);
  260.  
  261.         while (pEachEnum->Next(1, &varPointer, NULL) == S_OK)
  262.         {
  263.             pConfig = (IConfiguration*)varPointer.pdispVal;
  264.  
  265.             ProcessConfig(pConfig);    
  266.  
  267.             RELEASE(pConfig);
  268.         };
  269.     }
  270.     catch (...)
  271.     {
  272.         TRACE("CRegenWizardAppWiz::CustomizeProject");
  273.     };
  274.  
  275.     RELEASE(pConfigs);
  276. }
  277.  
  278.  
  279. // Here we define one instance of the CRegenWizardAppWiz class.  You can access
  280. //  m_Dictionary and any other public members of this class through the
  281. //  global RegenWizardaw.
  282. CRegenWizardAppWiz RegenWizardaw;
  283.  
  284.